package com.example.testdraw;

import java.util.logging.Level;
import java.util.logging.Logger;


import com.example.testdraw.charts.PieChart;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.RectF;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 这是我刚学习Android时，写的应用，很多地方都有很多问题
 * 使用的方法也有不少地方欠妥，有空再修改
 * com.example.testdraw.MainActivity
 * @author zhangyw
 */
public class MainActivity extends Activity {
	private RelativeLayout root = null;
	//GestureDetector detector = null;
	PieChart other = null;
	View yoyo = null;
	// private =null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		root = (RelativeLayout) findViewById(R.id.root);
		Float[] a = { (float) 0.2, (float) 0.3, (float) 0.5 };
		float[] b = { 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f };
		Logger.global.setLevel(Level.FINE);
		RectF oval = new RectF(20, 260, 420, 660);
		other = new PieChart(this, oval, b);
		root.addView(other);
		yoyo = new TextView(this);
		((TextView)yoyo).setText("点  我  换  焦  点  哟\n我要占两行！！\n三行");
		((TextView)yoyo).setTextSize(25);
		yoyo.setBackgroundColor(Color.BLUE);
		yoyo.setFocusable(true);
		yoyo.setFocusableInTouchMode(true);
		yoyo.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				/*System.out.print("this is textview:");
				System.out.println("requestFocus():"+v.requestFocus()+","+"requestFocusFromTouch:"+v.requestFocusFromTouch());
				System.out.println("textview: isfocused:"+v.isFocused());*/
				Logger.global.info("requestFocus():"+v.requestFocus()+","+"requestFocusFromTouch:"+v.requestFocusFromTouch());
				Logger.global.info("textview: isfocused:"+v.isFocused());
				return true;
			}
		});
		root.addView(yoyo);	
	}
	
	

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		// TODO Auto-generated method stub
		if(other.isFocused()){
/*			System.out.println("the piechart is focused");*/
			Logger.global.info("from dispatch"+"the piechart is focused");
			//detector.onTouchEvent(ev);
		}
		return super.dispatchTouchEvent(ev);
	}





	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
